<?php

	include_once('compare_display.php');
	include_once('classes/devices.php');
	include_once('classes/view.php');
	
	View::displayHeader();
	
	$MyObject = new Devices();
	$MyList = $MyObject -> GetMemory();
	DisplayScript();
	DisplayCompare::DisplayDevice($MyList, "memory", "Porównanie pamięci");
	
	$MyTable = array(	
						"rodzaj" => "Rodzaj: ",
						"pojemnosc" => "Pojemność: ",
						"max_taktowanie" => "Max. taktowanie [MHz]: ",
						"napiecie" => "Napięcie [V]: ",
						"ilosc_pin" => "Ilość pin: "
					);
					
	$MyTable2 = array(	
						"rodzajs" => "Rodzaj: ",
						"pojemnoscs" => "Pojemność: ",
						"max_taktowanies" => "Max. taktowanie [MHz]: ",
						"napiecies" => "Napięcie [V]: ",
						"ilosc_pins" => "Ilość pin: "
					);
	
	echo '<tr>';
	echo '<td>
			<table border="0" class="tableTest"><br />';
	
	foreach($MyTable as $MyId => $MyText){
		echo '	<tr>
					<td class="tableTd"><i><p align=\'right\'>'. $MyText . '&nbsp;&nbsp;</p></i></td>
					<td id="'. $MyId . '"></td>
				</tr>';
	}
	
	echo '</table>
		</td>
		<td>
			<table border="0" class="tableTest"><br />';
	
	foreach($MyTable2 as $MyId => $MyText){
		echo '	<tr>
					<td class="tableTd"><i><p align=\'right\'>'. $MyText . '&nbsp;&nbsp;</p></i></td>
					<td id="'. $MyId . '"></td>
				</tr>';
	}
	
	echo '</table>
		</td>
		</tr></table></div></form><br /><br /><br /><br />';
	
	View::displayFooter();

	function DisplayScript(){
		echo '<script type="text/javascript">
			var xmlHttp;
			var first;
			
			function showXmlDevice(pDevId, pKindDevice, pFirst){
				xmlHttp=GetXmlHttpObject();
				if (xmlHttp == null){
					alert ("Browser does not support HTTP Request");
					return;
				} 
				var url = "compare_get.php";
				url = url + "?kind_device=" + pKindDevice;
				url = url + "&dev_id=" + pDevId;
				url = url + "&first=" + pFirst;
				first = pFirst
				
				xmlHttp.onreadystatechange=stateChanged;
				xmlHttp.open("GET", url, true);
			 	xmlHttp.send(null);
			 }
			
			function stateChanged(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState == "complete"){
					xmlDoc=xmlHttp.responseXML;
					if (first == "1"){
						document.getElementById("rodzaj").innerHTML = xmlDoc.getElementsByTagName("rodzaj")[0].childNodes[0].nodeValue;
						document.getElementById("pojemnosc").innerHTML = xmlDoc.getElementsByTagName("pojemnosc")[0].childNodes[0].nodeValue;
						document.getElementById("max_taktowanie").innerHTML = xmlDoc.getElementsByTagName("max_taktowanie")[0].childNodes[0].nodeValue;
						document.getElementById("napiecie").innerHTML = xmlDoc.getElementsByTagName("napiecie")[0].childNodes[0].nodeValue;
						document.getElementById("ilosc_pin").innerHTML = xmlDoc.getElementsByTagName("ilosc_pin")[0].childNodes[0].nodeValue;
					} else {
						document.getElementById("rodzajs").innerHTML = xmlDoc.getElementsByTagName("rodzajs")[0].childNodes[0].nodeValue;
						document.getElementById("pojemnoscs").innerHTML = xmlDoc.getElementsByTagName("pojemnoscs")[0].childNodes[0].nodeValue;
						document.getElementById("max_taktowanies").innerHTML = xmlDoc.getElementsByTagName("max_taktowanies")[0].childNodes[0].nodeValue;
						document.getElementById("napiecies").innerHTML = xmlDoc.getElementsByTagName("napiecies")[0].childNodes[0].nodeValue;
						document.getElementById("ilosc_pins").innerHTML = xmlDoc.getElementsByTagName("ilosc_pins")[0].childNodes[0].nodeValue;
					}
				}
			} 
			
			function GetXmlHttpObject() { 
				var objXMLHttp=null;
				if (window.XMLHttpRequest){
					objXMLHttp=new XMLHttpRequest();
				} else if (window.ActiveXObject)  {
					objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				return objXMLHttp;
			}
				</script>';
	}
?>